//
//  NSArray+LSArray.m
//  breadPro
//
//  Created by 刘文超 on 2019/7/11.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "NSArray+LSArray.h"

@implementation NSArray (LSArray)
+(NSArray *)ls_splitArray:(NSArray *)array WithSubSize:(int)subSize;
{
    //将数组拆分成指定长度的个数
    unsigned long count = array.count % subSize == 0 ? (array.count/subSize) : (array.count /  subSize +1);
    //t用来保存指定长度数组的可变对象
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    for (int i =0 ; i<count; i++) {
        int index = i * subSize;
        //保存拆分的固定长度的数组原数的可变数组
        NSMutableArray *arr1 = [[NSMutableArray alloc]init];
        //移除子数组的个数
        [arr1 removeAllObjects];
        
        int j = index;
        //将数组下标拆分
        while (j<subSize*(i+1)&&j<array.count) {
            [arr1 addObject:[array objectAtIndex:j]];
            j += 1;
        }
        
        [arr addObject:[arr1 copy]];
    }
    return [arr copy];
}
@end
